package com.zhss.ddd.lottery.draw.risk.control.service;

import com.zhss.ddd.lottery.draw.risk.control.api.RiskControlApi;
import com.zhss.ddd.lottery.draw.risk.control.entity.RiskControlAlgorithm;
import com.zhss.ddd.lottery.draw.risk.control.spring.SpringContext;
import lombok.Data;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 风控算法
 */
@Service(
        version = "1.0.0",
        interfaceClass = RiskControlApi.class,
        cluster = "failfast",
        loadbalance = "roundrobin"
)
public class RiskControlService implements RiskControlApi {

    @Autowired
    private SpringContext springContext;

    /**
     * 执行具体的风控算法和逻辑，检查用户是否有刷单风险
     * @param userId 用户id
     */
    @Override
    public Boolean intercept(Long userId) {
        // 接收到RPC请求 还原出一个实体
        RiskControlAlgorithm riskControlAlgorithm = springContext.getBean(RiskControlAlgorithm.class);
        riskControlAlgorithm.setUserId(userId);
        return riskControlAlgorithm.intercept();
    }


}
